<?php

require "simple_html_dom/simple_html_dom.php";

$session_id = '';

class UploadPart {
	protected static $url;
	protected static $url_image;
	protected static $delimiter;
	protected static $instance;
	protected static $session_id;

	public function __construct() {
		static::$delimiter = uniqid();
	}

	public function setSession($session_id) {
		static::$session_id = $session_id;
		static::$url = 'https://www.turnitin.com/t_submit.asp?session-id=' . static::$session_id . '&lang=zh_hans&aid=';
	}

	public function setAid($aid) {

		$tmp = explode("&aid", static::$url);

		static::$url = $tmp[0] . '&aid=' . $aid;

		return static::$url;
	}

	public function putPart($param, $url) {
		$post_data = static::buildData($param);
		//var_dump($post_data);exit;
		$curl = curl_init($url);
		echo $url;
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_POST, true);
		curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
		curl_setopt($curl, CURLOPT_HTTPHEADER, [
			"Content-Type: multipart/form-data; boundary=" . static::$delimiter,
			"Content-Length: " . strlen($post_data),
		]);
		$response = curl_exec($curl);
		curl_close($curl);

		$result = json_decode($response, true);

		return $result;
	}

	public function getImage($uuid) {
		$curl = curl_init('https://www.turnitin.com/panda/get_submission_metadata.asp?session-id=' . static::$session_id . '&lang=zh_hans&skip_ready_check=0&uuid=' . $uuid);
		$post_data = [];
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_POST, true);
		curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
		//curl_setopt($curl, CURLOPT_HTTPHEADER, [
		//	"Content-Length: " . strlen($post_data),
		//]);
		$response = curl_exec($curl);
		curl_close($curl);

		$result = json_decode($response, true);

		return $result;
	}

	public function submitResult($uuid) {
		$curl = curl_init('https://www.turnitin.com/submit_confirm.asp?lang=zh_hans&session-id=' . static::$session_id . '&data-state=confirm&uuid=' . $uuid);
		$post_data = [];
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_POST, true);
		curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
		//curl_setopt($curl, CURLOPT_HTTPHEADER, [
		//  "Content-Length: " . strlen($post_data),
		//]);
		$response = curl_exec($curl);
		curl_close($curl);

		$result = json_decode($response, true);

		return $result;
	}

	public function getSessionId() {
		$curl = curl_init('https://www.turnitin.com/login_page.asp?lang=en_us');
		$post_data = ['email' => 'turnitin_immlyl77@gmail.com', 'user_password' => 'ABC12345678'];
		//$post_data = "email=turnitin_immlyl77@gmail.com&user_password=ABC12345678";
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_POST, true);
		curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
		curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
		$response = curl_exec($curl);
		curl_close($curl);

		//echo $response;

		$html = new simple_html_dom();

		$html->load($response);

		$session_input = $html->find('input[name=session_id]', 0);

		$session_id = $session_input->value;

		return $session_id;
	}

	public function Cget($url, $session_id) {
		$curl = curl_init($url);
		//$post_data = "email=turnitin_immlyl77@gmail.com&user_password=ABC12345678";
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36');
		$cookie = 'turnitin_region_selection=dismissed; _gcl_au=1.1.1241897834.1639563865; _ga=GA1.2.1090852546.1639563865; _ym_uid=1639563867700281325; _ym_d=1639563867; loginIntent=TRUE; test_cookie=1; xhfaculty=0; NPS_8984eeea_last_seen=1639563921031; __utmc=162339897; __utmz=162339897.1639563923.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); lang=zh_hans; fileDownload=true; _gid=GA1.2.247682694.1640759509; XSRF-TOKEN=eyJpdiI6IjN1cTl6clhONjRCS2FvNUJpXC93ZzZBPT0iLCJ2YWx1ZSI6IjJ4NUpzZVYrV29MYU9sK05WRDU1b0oyK3ZhUUdlUFhpenVKcDR5Rnd4bElleXFlY2NvTmhaSWlPd0tHY2Y0M0xEQkE2SDZJUGdsZ3Z6M0dQZWVyWHdRPT0iLCJtYWMiOiJiNTZhYmEzOTIxMDkxNTI0MDM3ZjJmZGUyOTEzMTIwYjNjZmNlZmZjMDk5ZWIyMmEzN2E3Yzc4NGU0OTQxMTMxIn0%3D; laravel_session=eyJpdiI6IjgrVTZ1M3dqNjZuWnQ2c0NyVEd2Y2c9PSIsInZhbHVlIjoiK2VqdWxBUHNyUHB3YW9vYU9JaEhGTmR2ZXhEWGNIRmZpdSsyR3RCV0ZOVFwvbkREeXBVbGI1XC9tXC9Yd2xRVE5lQVljc3N4NnBZM1ZxQ0NqZDNlTDFpMlE9PSIsIm1hYyI6ImNkYzQwMTRjMDMzMWNlYzNlZTFjZjQ5MjJjNmQ3NDIxY2E4YmFkMDQ3ZmNlNWIzZDMzYjE3ZmE4YjJjZWI3NDkifQ%3D%3D; _clck=1drinok|1|exo|0; OptanonConsent=isGpcEnabled=0&datestamp=Wed+Dec+29+2021+17%3A35%3A35+GMT%2B0800+(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)&version=6.24.0&isIABGlobal=false&hosts=&consentId=942b9654-9188-4d1a-8255-590739509c4b&interactionCount=1&landingPath=NotLandingPage&groups=C0001%3A1%2CC0004%3A1%2CC0003%3A1%2CC0002%3A1&AwaitingReconsent=false; _uetsid=01f7ece0687111ec9b7535b759c1abab; _uetvid=2d4d83505d9111ecaf74a572fc1e90ee; _ym_isad=2; _clsk=1bj0mea|1640770941418|2|1|f.clarity.ms/collect; session-id=' . $session_id . '; legacy-session-id=' . $session_id . '; t=58506b1138c64567bf611679090f329c; __utma=162339897.1090852546.1639563865.1640273163.1640773099.4; __utmt=1; NPS_8984eeea_throttle=1640816299156; __utmb=162339897.5.10.1640773099';

		curl_setopt($curl, CURLOPT_COOKIE, $cookie);
		$response = curl_exec($curl);
		curl_close($curl);

		return $response;
	}

	//访问首页，找text的链接
	public function findHome($session_id) {
		$url = 'https://www.turnitin.com/t_home.asp?svr=55&lang=zh_hans&r=36.8181785214929';

		static::$session_id = $session_id;

		$response = static::Cget($url, static::$session_id);

		$is_login = 1;

		$html = new simple_html_dom();

		//var_dump($response);

		$html->load($response);

		$footer = $html->find('.nav__item__footer', 0);

		$href_list = [];

		if ($footer) {
			$a = $footer->find('a', 0);
			if ($a) {
				$txt = $a->innertext;
				if ($txt == 'Create Account') {
					$is_login = 0;
				}
			}

			if ($is_login == 0) {
				$session_id = static::getSessionId();

				static::$session_id = $session_id;

				$response = static::Cget($url, static::$session_id);
			}

			$html->load($response);
		}

		$class_name_list = $html->find('.class_name');

		foreach ($class_name_list as $k => $class_name) {
			$a = $class_name->find('a', 0);
			if ($a && strstr($a->href, '33181582')) {
				$href_list[] = $a->href;
			}
		}

		return $href_list;

	}

	public function testSession($session_id) {
		$url = 'https://www.turnitin.com/t_home.asp?svr=55&lang=zh_hans&r=36.8181785214929';

		$response = static::Cget($url, static::$session_id);

		$is_login = 1;

		$html = new simple_html_dom();

		$html->load($response);

		$footer = $html->find('.nav__item__footer', 0);

		$href_list = [];

		if ($footer) {
			$a = $footer->find('a', 0);
			if ($a) {
				$txt = $a->innertext;
				if ($txt == 'Create Account') {
					$is_login = 0;
				}
			}
		} else {
			$class_name_list = $html->find('.class_name');

			foreach ($class_name_list as $k => $class_name) {
				$a = $class_name->find('a', 0);
				if ($a) {
					$href_list[] = $a->href;
				}
			}

		}

		return $href_list;
	}

	public function url_decode($url) {
		$tmp = str_replace('&#61;', '=', $url);

		$url = str_replace('&amp;', '&', $tmp);

		return $url;
	}

	//访问作业
	public function findWork($path) {
		$url = 'https://www.turnitin.com/' . $path;

		$url = static::url_decode($url);

		$response = static::Cget($url, static::$session_id);

		$html = new simple_html_dom();

		$html->load($response);

		$inbox_list = $html->find('.assgn-inbox');

		$href_list = [];

		foreach ($inbox_list as $k => $inbox) {
			$a = $inbox->find('a', 0);
			if ($a) {
				$href_list[] = $a->href;
			}
		}

		return $href_list;
	}

	//findResult
	public function findResult($path) {
		$url = 'https://www.turnitin.com/' . $path;

		$url = static::url_decode($url);

		echo 'url=' . $url;

		$response = static::Cget($url, static::$session_id);

		$html = new simple_html_dom();

		$html->load($response);

		$inbox_list = $html->find('.inbox_table tr');

		$href_list = [];

		$list = [];

		foreach ($inbox_list as $k => $inbox) {

			$author = $inbox->find('.ibox_author ', 0);

			if ($author) {

				$author = $inbox->find('.ibox_author ', 0)->innertext;

				$title = $inbox->find('.ibox_title', 0)->find('a', 0)->innertext;

				$or_percentage = $inbox->find('.or-percentage', 0);

				$percentage = $or_percentage ? $or_percentage->innertext : '';

				$download = $inbox->find('.ibox_title', 0)->find('a', 0);

				$download_href = $download ? $download->onclick : '';

				//logger('download_href', download_href);

				$download_href_tmp = '';

				if ($onclick) {
					$href_tmp = explode("'", $download_href);

					$download_href_tmp = $href_tmp[1];
				}

				$pid_item = $inbox->find('.pid', 0);

				$pid = $pid_item ? $pid_item->innertext : "";

				$date_item = $inbox->find('.class_status', 0);

				$date = $date_item ? $date_item->innertext : '';

				$tmp = ['author' => $author, 'title' => $title, 'percentage' => $percentage, 'download_href' => $download_href_tmp
					, 'pid' => $pid, 'date' => $date];

				$list[] = $tmp;
			}
		}

		return $list;
	}

	public function similarity($oid, $session_id) {
		$curl = curl_init('https://ev.turnitin.com/paper/' . $oid . '/similarity/options?lang=en_us&cv=1&output=json&tl=0');

		echo 'url4=' . 'https://ev.turnitin.com/paper/' . $oid . '/similarity/options?lang=en_us&cv=1&output=json&tl=0';

		$post_data = ['exclude_assignment_template' => null, 'exclude_biblio' => 1, 'exclude_quotes' => 1, 'exclude_small_matches' => 1, 'id' => $oid . '_0', 'paper' => $oid, 'translate_language' => 0];

		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
		curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
		curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36');
		$cookie = 'turnitin_region_selection=dismissed; _gcl_au=1.1.1241897834.1639563865; _ga=GA1.2.1090852546.1639563865; _ym_uid=1639563867700281325; _ym_d=1639563867; loginIntent=TRUE; test_cookie=1; xhfaculty=0; NPS_8984eeea_last_seen=1639563921031; __utmc=162339897; __utmz=162339897.1639563923.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); lang=en_us; fileDownload=true; _gid=GA1.2.247682694.1640759509; XSRF-TOKEN=eyJpdiI6IjN1cTl6clhONjRCS2FvNUJpXC93ZzZBPT0iLCJ2YWx1ZSI6IjJ4NUpzZVYrV29MYU9sK05WRDU1b0oyK3ZhUUdlUFhpenVKcDR5Rnd4bElleXFlY2NvTmhaSWlPd0tHY2Y0M0xEQkE2SDZJUGdsZ3Z6M0dQZWVyWHdRPT0iLCJtYWMiOiJiNTZhYmEzOTIxMDkxNTI0MDM3ZjJmZGUyOTEzMTIwYjNjZmNlZmZjMDk5ZWIyMmEzN2E3Yzc4NGU0OTQxMTMxIn0%3D; laravel_session=eyJpdiI6IjgrVTZ1M3dqNjZuWnQ2c0NyVEd2Y2c9PSIsInZhbHVlIjoiK2VqdWxBUHNyUHB3YW9vYU9JaEhGTmR2ZXhEWGNIRmZpdSsyR3RCV0ZOVFwvbkREeXBVbGI1XC9tXC9Yd2xRVE5lQVljc3N4NnBZM1ZxQ0NqZDNlTDFpMlE9PSIsIm1hYyI6ImNkYzQwMTRjMDMzMWNlYzNlZTFjZjQ5MjJjNmQ3NDIxY2E4YmFkMDQ3ZmNlNWIzZDMzYjE3ZmE4YjJjZWI3NDkifQ%3D%3D; _clck=1drinok|1|exo|0; OptanonConsent=isGpcEnabled=0&datestamp=Wed+Dec+29+2021+17%3A35%3A35+GMT%2B0800+(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)&version=6.24.0&isIABGlobal=false&hosts=&consentId=942b9654-9188-4d1a-8255-590739509c4b&interactionCount=1&landingPath=NotLandingPage&groups=C0001%3A1%2CC0004%3A1%2CC0003%3A1%2CC0002%3A1&AwaitingReconsent=false; _uetsid=01f7ece0687111ec9b7535b759c1abab; _uetvid=2d4d83505d9111ecaf74a572fc1e90ee; _ym_isad=2; _clsk=1bj0mea|1640770941418|2|1|f.clarity.ms/collect; session-id=' . $session_id . '; legacy-session-id=' . $session_id . '; t=58506b1138c64567bf611679090f329c; __utma=162339897.1090852546.1639563865.1640273163.1640773099.4; __utmt=1; NPS_8984eeea_throttle=1640816299156; __utmb=162339897.5.10.1640773099';

		curl_setopt($curl, CURLOPT_COOKIE, $cookie);
		//curl_setopt($curl, CURLOPT_HTTPHEADER, [
		//  "Content-Length: " . strlen($post_data),
		//]);
		$response = curl_exec($curl);
		curl_close($curl);

		var_dump($response);

		$result = json_decode($response, true);

		return $result;
	}

	//获取下载链接2
	public function findDownFile2($oid, $session_id) {
		$curl = curl_init('https://ev.turnitin.com/paper/' . $oid . '/queue_pdf?lang=zh_hans&cv=1&output=json');

		echo 'url3=' . 'https://ev.turnitin.com/paper/' . $oid . '/queue_pdf?lang=zh_hans&cv=1&output=json';

		$post_data = ['as' => 1, 'or_type' => 'similarity', 'or_translate_language' => 0];
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_POST, true);
		curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
		curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36');
		$cookie = 'turnitin_region_selection=dismissed; _gcl_au=1.1.1241897834.1639563865; _ga=GA1.2.1090852546.1639563865; _ym_uid=1639563867700281325; _ym_d=1639563867; loginIntent=TRUE; test_cookie=1; xhfaculty=0; NPS_8984eeea_last_seen=1639563921031; __utmc=162339897; __utmz=162339897.1639563923.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); lang=zh_hans; fileDownload=true; _gid=GA1.2.247682694.1640759509; XSRF-TOKEN=eyJpdiI6IjN1cTl6clhONjRCS2FvNUJpXC93ZzZBPT0iLCJ2YWx1ZSI6IjJ4NUpzZVYrV29MYU9sK05WRDU1b0oyK3ZhUUdlUFhpenVKcDR5Rnd4bElleXFlY2NvTmhaSWlPd0tHY2Y0M0xEQkE2SDZJUGdsZ3Z6M0dQZWVyWHdRPT0iLCJtYWMiOiJiNTZhYmEzOTIxMDkxNTI0MDM3ZjJmZGUyOTEzMTIwYjNjZmNlZmZjMDk5ZWIyMmEzN2E3Yzc4NGU0OTQxMTMxIn0%3D; laravel_session=eyJpdiI6IjgrVTZ1M3dqNjZuWnQ2c0NyVEd2Y2c9PSIsInZhbHVlIjoiK2VqdWxBUHNyUHB3YW9vYU9JaEhGTmR2ZXhEWGNIRmZpdSsyR3RCV0ZOVFwvbkREeXBVbGI1XC9tXC9Yd2xRVE5lQVljc3N4NnBZM1ZxQ0NqZDNlTDFpMlE9PSIsIm1hYyI6ImNkYzQwMTRjMDMzMWNlYzNlZTFjZjQ5MjJjNmQ3NDIxY2E4YmFkMDQ3ZmNlNWIzZDMzYjE3ZmE4YjJjZWI3NDkifQ%3D%3D; _clck=1drinok|1|exo|0; OptanonConsent=isGpcEnabled=0&datestamp=Wed+Dec+29+2021+17%3A35%3A35+GMT%2B0800+(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)&version=6.24.0&isIABGlobal=false&hosts=&consentId=942b9654-9188-4d1a-8255-590739509c4b&interactionCount=1&landingPath=NotLandingPage&groups=C0001%3A1%2CC0004%3A1%2CC0003%3A1%2CC0002%3A1&AwaitingReconsent=false; _uetsid=01f7ece0687111ec9b7535b759c1abab; _uetvid=2d4d83505d9111ecaf74a572fc1e90ee; _ym_isad=2; _clsk=1bj0mea|1640770941418|2|1|f.clarity.ms/collect; session-id=' . $session_id . '; legacy-session-id=' . $session_id . '; t=58506b1138c64567bf611679090f329c; __utma=162339897.1090852546.1639563865.1640273163.1640773099.4; __utmt=1; NPS_8984eeea_throttle=1640816299156; __utmb=162339897.5.10.1640773099';

		curl_setopt($curl, CURLOPT_COOKIE, $cookie);
		//curl_setopt($curl, CURLOPT_HTTPHEADER, [
		//  "Content-Length: " . strlen($post_data),
		//]);
		$response = curl_exec($curl);
		curl_close($curl);

		var_dump($response);

		$result = json_decode($response, true);

		return $result;
	}

	//获得下载文件链接
	//findDownFile
	//访问作业
	public function findDownFile($path) {
		$url = 'https://www.turnitin.com/' . $path;

		$url = static::url_decode($url);

		$response = static::Cget($url, static::$session_id);

		$html = new simple_html_dom();

		$html->load($response);

		$li_list = $html->find('li');

		$href_list = [];

		foreach ($li_list as $k => $li_info) {
			$a = $li_info->find('a', 0);
			if ($a) {
				$href_tmp = $a->href;
				if ($href_tmp) {
					$href_list[] = $href_tmp;
				}
			}
		}

		return $href_list;
	}

	public function findRealDownFile2($url) {

		echo 'url2=' . $url;

		$response = static::Cget($url, static::$session_id);

		var_dump($response);

		$json = json_decode($response, true);

		return $json;
	}

	public function DownFile($url) {

		//echo 'url=' . $url;

		$response = static::Cget($url, static::$session_id);

		return $response;
	}

	public function findRealDownFile($path) {
		$url = 'https://www.turnitin.com/' . $path;

		$url = static::url_decode($url);

		$response = static::Cget($url, static::$session_id);

		$href_tmp = explode("'", $response);

		$result = $href_tmp[1];

		return $result;
	}

	private static function buildData($param) {
		$data = '';
		$eol = "\r\n";
		$upload = $param['upload'];
		unset($param['upload']);

		$filename = $param['userfile'];

		unset($param['userfile']);

		foreach ($param as $name => $content) {
			$data .= "--" . static::$delimiter . "\r\n"
				. 'Content-Disposition: form-data; name="' . $name . "\"\r\n\r\n"
				. $content . "\r\n";
		}

		$tmp_name = explode(".", $filename);

		$suffix = $tmp_name[1];

		if ($suffix == 'doc') {
			$suffix = 'wps-writer';
		}

		// 拼接文件流
		$data .= "--" . static::$delimiter . $eol
			. 'Content-Disposition: form-data; name="userfile"; filename="' . $filename . '"' . "\r\n"
			. 'Content-Type:application/' . $suffix . "\r\n\r\n";

		$data .= $upload . "\r\n";
		$data .= "--" . static::$delimiter . "--\r\n";
		return $data;
	}

	public static function getInstance($session_id) {
		static::$session_id = $session_id;
		if (!static::$instance) {
			static::$instance = new static();
		}
		return static::$instance;
	}

}

$fields = array(
	'userfile' => 'test.docx',
	'upload' => file_get_contents('https://turnitin.shenzhenbenwo.com/uploads/api/202201/tmp_7d5c9a1d66715e0204082e39b48e6da9.docx.pdf'),
	'async_request' => 1,
	'userID' => '',
	'author_first' => '张',
	'author_last' => '吴',
	'title' => '好东西',
	'db_doc' => '',
	'dropbox_filename' => '',
	'google_doc' => '',
	'google_auth_uri' => '',
	'token' => '',
	'submit_button' => '',
);

$session_id = '7502db38c8294a0aa37c219818ad7413';

$aid = '116339659';

//echo $session_id;

$upload = UploadPart::getInstance($session_id);

$session_id = $upload->getSessionId();

echo $session_id;

$upload->setSession($session_id);

$url = $upload->setAid($aid);

// $result = $upload->findHome($session_id);

// //var_dump($result);exit;

// $work_result = $upload->findWork($result[0]);

// $data = $upload->findResult($work_result[0]);

// //var_dump($data);

// $part = $upload->putPart($fields, $url);

// var_dump($part);

// $uuid = $part['uuid'];

// echo $uuid;

// $status = 0;

// $image_result = [];

// while ($status == 0) {
// 	$image_result = $upload->getImage($uuid);
// 	$status = $image_result['status'];
// }

// //print_r($image_result);

// $submit_result = $upload->submitResult($uuid);

// //print_r($submit_result);

// $oid = $submit_result['oid'];

// echo 'oid=' . $oid;

// //$session_id = '13f1f16e81b14628acd0d507633a952a';

// //$oid = '1744682211';

// $upload = UploadPart::getInstance($session_id);

// $session_id = $upload->getSessionId();

// //echo $session_id;

// $upload->setSession($session_id);

// $result = $upload->findHome($session_id);

// //var_dump($result);exit;

// $work_result = $upload->findWork($result[0]);

// $i = 1;

// $info = [];

// while (!$info) {
// 	$data_result = $upload->findResult($work_result[0] . '&pg=' . $i);
// 	var_dump($data_result);
// 	foreach ($data_result as $k => $v) {
// 		echo 'pid=' . $v['pid'];
// 		if ($v['pid'] == $oid) {
// 			$info = $v;
// 		}
// 	}
// 	$i++;
// }

// var_dump($info);

// sleep(5);

$oid = '1747039335';

$session_id = '7502db38c8294a0aa37c219818ad7413';

$similarity = $upload->similarity($oid, $session_id);

// $down_result = $upload->findDownFile2($oid, $session_id);

// $real_down_url = $down_result['url'];

// $real_down_url = $real_down_url . '&cv=1&output=json';

// echo $real_down_url;exit;

// $last_result = $upload->findRealDownFile2($real_down_url);

// $ready = $last_result['ready'];

// while ($ready == 0) {
// 	$last_result = $upload->findRealDownFile2($real_down_url);
// 	$ready = $last_result['ready'];
// 	sleep(1);
// }

// $last_url = $last_result['url'];

// echo 'last_url=' . $last_url;

// $down_file = $upload->DownFile($last_url);

// $put_back = file_put_contents('/www/wwwroot/puppet_task1/old2/test2.pdf', $down_file);

// var_dump($put_back);exit;

exit();